/**
 * 
 */
 	  var map = null;
      var infowindow;

	/* metodo executado ao carregar a pagina configurando o mapa */	
	function carregar(){
		
	    var latlng = new google.maps.LatLng(-23.561096,-46.656107);
	    var myOptions = {
	        zoom: 15,
	        center: latlng,
	        mapTypeId: google.maps.MapTypeId.ROADMAP
	    };

	    //criando o mapa
	    map = new google.maps.Map(document.getElementById("map"), myOptions);
	    
	  
	    
	              
	}

	function pesquisar(){
				
	    var endereco = document.getElementById("endereco").value ;
	    
	    if (endereco == null || endereco == "") {
	    	
			alert("Informe um endereço de destino!");
			
		}	
	    
	    geocoder = new google.maps.Geocoder();
	    geocoder.geocode({'address':endereco}, function(results, status){
	        if( status = google.maps.GeocoderStatus.OK){
	        lat = results[0].geometry.location.lat();
		    lng = results[0].geometry.location.lng();
		    initialize(lat, lng); 
		    
		    
		    var praca = new google.maps.LatLng(-23.56916,-46.713356);
		    marcadorPraca = new google.maps.Marker({
		        position: praca,
		        map: map,
		        title:"Estacionamento SGE"
		    });
		    
		    var infowindow = new google.maps.InfoWindow({
		        content: "<html><head></head><span style='font-weight: bold;'>Estacionamento SGE</span><br/><br/><span styleClass='txtNegrito'>Preço: R$ 5,00 hrs</span><br/><span styleClass='txtNegrito'>Av. Vital Brasil 1000 - Butantã<br/> São Paulo, 05503-000</span><br/><br/><a href='termo.jsf'>Fazer Reserva</a><br/></html>"
		    });
		             
		    google.maps.event.addListener(marcadorPraca, 'click', function(event) {
		    	infowindow.open(map,marcadorPraca);
		    });
		    
			
	        }	
	    });
	    
	   
	    
	   	    
	}

	
      function initialize(lat, lng) {
    	      	  
          var pyrmont = new google.maps.LatLng(lat, lng);
          var distancia = document.getElementById("raio").value;

          map = new google.maps.Map(document.getElementById('map'), {
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              center: pyrmont,
              zoom: 15
          });
          
    	  
    	  if (distancia == null || distancia == "") {
    		  
    		  distancia = 200;
    		  
    	  }

         var request = {
             location: pyrmont,
             radius: distancia,
             types: ['parking']
         };

        infowindow = new google.maps.InfoWindow();
        var service = new google.maps.places.PlacesService(map);
        service.search(request, callback);
               
      }

      function callback(results, status) {
          if (status == google.maps.places.PlacesServiceStatus.OK) {
              for (var i = 0; i < results.length; i++) {
                  createMarker(results[i]);
              }
          }
          
         
      }

      function createMarker(place) {
          var placeLoc = place.geometry.location;
          var marker = new google.maps.Marker({
              map: map,
              position: place.geometry.location
          });

          google.maps.event.addListener(marker, 'click', function() {
              infowindow.setContent(place.name);
              infowindow.open(map, this);
          });
      }